package com.mkj.basic;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * @Author Arrebol
 * @Date 2024/8/6 18:25
 * @Project graphical programming
 * @Description：
 * 输入对话框演示
 */
public class InputDialogTest {

    JFrame frame = new JFrame("测试输入对话框");
    TextArea textArea = new TextArea(6,30);
    JButton button = new JButton(new AbstractAction("弹出输入对话框") {
        @Override
        public void actionPerformed(ActionEvent e) {
            //弹出输入对话框
            String result = JOptionPane.showInputDialog(frame, "请填写您的手机号", "输入对话框", JOptionPane.INFORMATION_MESSAGE);
            textArea.append(result+"\n");
        }
    });
    public void init(){
        //组装视图
        frame.add(textArea);
        frame.add(button,BorderLayout.SOUTH);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        new InputDialogTest().init();
    }
}
